# Contributor: Konstantin Kulikov <k.kulikov2@gmail.com>
# Maintainer: Konstantin Kulikov <k.kulikov2@gmail.com>
pkgname=grafana-image-renderer
pkgver=2.0.0
pkgrel=0
pkgdesc="Grafana Backend Plugin that handles rendering of panels & dashboards to PNGs using headless chrome"
url="https://github.com/grafana/grafana-image-renderer"
arch="x86_64" # Requires chromium, aarch64 and armv7 doesn't build because of grpc.
license="Apache-2.0"
makedepends="yarn"
depends="nodejs ttf-opensans chromium ca-certificates"
options="!check" # Has no test suite.
install="$pkgname.pre-install"
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/grafana/grafana-image-renderer/archive/v$pkgver.tar.gz
	$pkgname.initd $pkgname.confd $pkgname.json"

build() {
	export CHROME_BIN="/usr/bin/chromium-browser"
	export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"

	# Don't pollute our aports repo with husky git hooks.
	# This command also acts as implicit "yarn install".
	yarn remove --pure-lockfile -W husky

	yarn build
}

package() {
	install -Dm755 "$srcdir/$pkgname.initd" "$pkgdir/etc/init.d/$pkgname"
	install -Dm644 "$srcdir/$pkgname.confd" "$pkgdir/etc/conf.d/$pkgname"
	install -Dm644 "$srcdir/$pkgname.json" "$pkgdir/etc/$pkgname.json"
	install -dm755 "$pkgdir/usr/share/$pkgname"
	cp -r "$builddir/node_modules" "$builddir/build" "$builddir/proto" "$pkgdir/usr/share/$pkgname/"
}

sha512sums="e14cb35bdd57d5a4f66a3345dac51ea799764ad1f3e3874b8be951e1e74896708cb877eb60124094275770da13bd51538bc0ae979f7648f783a1b28d227645eb  grafana-image-renderer-2.0.0.tar.gz
06faad0f5abecf434c014ca91dccf3f07f18d96a8f526c3c1d2384cba8db44db5fe2b2165d8fc12a8fe8d121135077b0c70158ee29ebb1bfba8dd2a3110b349c  grafana-image-renderer.initd
88a119ad18fbde490ab9213487ae16b8aeeb65437275a1112f7423fa581a7470e6fb68654c2fd439afa68c0333aeefd0711f3fffd53615fa51d0702c80ed1c1b  grafana-image-renderer.confd
fe68bee6815de89f01edf49997d3be01ab5f3bf8c51cfc7d3d893e797f0beb44c2d7c67e5f750ab37588bf3475957774541cb4b37e1ee85ad98d18fbf2cb14e8  grafana-image-renderer.json"
